#include<iostream>
using namespace std;

class Date
{
    friend istream& operator>>(istream& in, Date& d);
    friend ostream& operator<<(ostream& out, const Date& d);
public:
    Date(int year, int month, int day)
        :_year(year)
        , _month(month)
        , _day(day)
    {}
    int GetMonthDay(int year, int month)
    {
        int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
        if (month == 2
            && ((year % 4 == 0) && (year % 100 != 0))
            || (year % 400 == 0))
        {
            return 29;
        }
        else
        {
            return arr[month];
        }
    }
    Date& operator+=(int day)
    {
        _day += day;
        while (_day > GetMonthDay(_year, _month))
        {
            _day -= GetMonthDay(_year, _month);
            ++_month;
            if (_month > 12)
            {
                _month = 1;
                ++_year;
            }
        }
        return *this;
    }
private:
    int _year;
    int _month;
    int _day;
};

istream& operator>>(istream& in, Date& d)
{
    in >> d._year >> d._month >> d._day;
    return in;
}
ostream& operator<<(ostream& out, const Date& d)
{
    if (d._month >= 10 && d._day >= 10)
    {
        out << d._year << "-" << d._month << "-" << d._day;
    }
    else if (d._month >= 10 && d._day < 10)
    {
        out << d._year << "-" << d._month << "-" << "0" << d._day;
    }
    else if (d._month < 10 && d._day >= 10)
    {
        out << d._year << "-" << "0" << d._month << "-" << d._day;
    }
    else if (d._month < 10 && d._day < 10)
    {
        out << d._year << "-" << "0" << d._month << "-" << "0" << d._day;
    }

    return out;
}

int main()
{
    int m = 0;
    cin >> m;
    while (m--)
    {
        Date d(2000, 1, 1);
        cin >> d;
        int day = 0;
        cin >> day;
        d += day;
        cout << d << endl;
    }
    return 0;
}